package view.tool
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;

import framework.proxy.ComponentProxy;
import framework.view.components.button.ButtonProxy;

/**
 * ToolProxy
 * @author jliang
 * 
 */
public class ToolProxy extends ComponentProxy
{
	//==========================================================================
	//  Constructor
	//==========================================================================
	public function ToolProxy()
	{
		super();
	}
	//==========================================================================
	//  Variables
	//==========================================================================
	private var moveBtn:ButtonProxy;
	private var rotateBtn:ButtonProxy;
	private var sellBtn:ButtonProxy;
	private var stashBtn:ButtonProxy;
	//==========================================================================
	//  Properties
	//==========================================================================
	private var _enable:Boolean = false;

	public function get enable():Boolean
	{
		return _enable;
	}

	public function set enable(value:Boolean):void
	{
		_enable = value;
		
		skin.visible = skin.mouseChildren = skin.mouseEnabled = value;
		
		if (value)
		{
			if (skin.stage) skin.stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpOnStageHandler, true);
		}
		else
		{
			if (skin.stage) skin.stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUpOnStageHandler, true);
		}
	}

	//==========================================================================
	//  Overridden methods: ComponentProxy
	//==========================================================================
	override public function parse(target:MovieClip):void
	{
		super.parse(target);
		
		moveBtn = new ButtonProxy();
		moveBtn.parse(skin["moveBtn"]);
		moveBtn.onClick = clickToMoveHandler;
		
		rotateBtn = new ButtonProxy();
		rotateBtn.parse(skin["rotateBtn"]);
		rotateBtn.onClick = clickToRotateHandler;
		
		sellBtn = new ButtonProxy();
		sellBtn.parse(skin["sellBtn"]);
		sellBtn.onClick = clickToSellHandler;
		
		stashBtn = new ButtonProxy();
		stashBtn.parse(skin["stashBtn"]);
		stashBtn.onClick = clickToStashHandler;
		
		enable = false;
	}
	//==========================================================================
	//  Public methods
	//==========================================================================
	public function open():void
	{
		enable = true;
	}
	
	public function close():void
	{
		enable = false;
	}
	//==========================================================================
	//  Event handlers
	//==========================================================================	
	private function mouseUpOnStageHandler(event:Event):void		
	{
		if (enable)
		{
			enable = false;
		}
	}
	
	private function clickToMoveHandler():void
	{
		//ObjectControlManager.active(ControlType.MOVE);
	}
	
	private function clickToRotateHandler():void
	{
		//ObjectControlManager.active(ControlType.ROTATE);
	}
	
	private function clickToSellHandler():void
	{
		//ObjectControlManager.active(ControlType.SELL);
	}
	
	private function clickToStashHandler():void
	{
		//ObjectControlManager.active(ControlType.STASH);
	}
}
}